#include "startpushbutton.h"

StartPushButton::StartPushButton(QString normalImg,QString pressImg)
{
    this->m_normalImgPath=normalImg;
    this->m_pressImgPath=pressImg;


    QPixmap Pix;
    bool ret = Pix.load(m_normalImgPath);
    if(!ret)
    {
        QMessageBox::warning(this,"警告","文件"+m_normalImgPath+"不存在");
    }
    else
    {
        this->setFixedSize(25,25);
        Pix = Pix.scaled(this->width(),this->height());
        this->setIcon(QIcon(Pix));
    }
    //如果左键按下切换到被按下的图片
    connect(this,&QPushButton::pressed,[=](){
        QPixmap press;
        bool nret = press.load(this->m_pressImgPath);
        if(!nret)
        {
            QMessageBox::warning(this,"警告","文件"+m_pressImgPath+"不存在");
        }
        else
        {
            press = press.scaled(this->width()+4,this->height()+4);
            this->setIcon(QIcon(press));
        }
    });
    //如果左键松开切换回原来的图片
    connect(this,&QPushButton::released,[=](){
        QPixmap release;
        bool nret = release.load(this->m_normalImgPath);
        if(!nret)
        {
            QMessageBox::warning(this,"警告","文件"+m_pressImgPath+"不存在");
        }
        else
        {
            release = release.scaled(this->width(),this->height());
            this->setIcon(QIcon(release));
        }
    });
}
